#ifndef __HEAD__
#define __HEAD__
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <pthread.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include "taskQueue.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <shadow.h>
#include <crypt.h>
#include <stdbool.h>
#include <syslog.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <mysql/mysql.h>
#include <sys/mman.h>
#define LOG_CHECK(opt, arg)                                                                                           \
{                                                                                                                     \
    time_t tmp = time(NULL);                                                                                            \
    char buf[1024] = {0};                                                                                           \
    if (strcmp(opt, "login") == 0) {                                                                                  \
        syslog(LOG_DEBUG, "user: %s login core_file:%s : %d ,time : %s", arg, __FILE__, __LINE__, ctime_r(&tmp, buf));  \
    } else {                                                                                                          \
        syslog(LOG_DEBUG, "cmd: %s dir : %s  core_file:%s : %d , time : %s", opt, arg, __FILE__, __LINE__, ctime_r(&tmp, buf)); \
    }                                                                                                                 \
}
#define MYSQL_CONNECT_CHECK(ret, mysql){    \
    if(ret == NULL)     \
        fprintf(stderr, "%s\n", mysql_error(mysql));    \
}
#define MYSQL_QUERY_CHECK(ret, mysql){  \
    if(ret != 0)    \
        fprintf(stderr, "%s\n", mysql_error(mysql)); \
}
typedef struct threadPool_s{
    int workerNum;//工作线程数量也就是线程池的大小
    pthread_t* tidArry;//线程的tid合集
    taskQueue_t taskQueue;//任务队列
    pthread_mutex_t mutex;
    pthread_cond_t cond;
    int exitflag;
}threadPool_t;

typedef struct train_s{
     int length;
     char data[4096];
}train_t;
typedef struct stacknode_s{
    char* data;
    struct stacknode_s* next;
}stacknode_t;

typedef struct Stack_s{
    stacknode_t* top;
    stacknode_t* bottom;
    int stacksize;
}Stack_t;

int tcpInit(const char* ip,const char* port,int* sockfd);
int makeWorker(threadPool_t* pthreadPool);
int epollAdd(int epfd,int fd);
int epollDel(int epfd,int fd);
int recvn(int netfd, void* buf, int length);
int loginFunc(int netfd,char* name,MYSQL* mysql);
int getCurFolder(char* username,MYSQL* mysql);
int getAbsolutePath(int id_now,const char* path,const char* username,MYSQL* mysql);
int mkdirFunc(int id_now,const char* arg,char* user,MYSQL* mysql);
int rmdirFunc(int id_now,const char *arg,const char* user,MYSQL *mysql);
bool isDir(int id,MYSQL* mysql);
bool isTomb(int id,MYSQL* mysql);
void idToPath(int id,char* path,MYSQL* mysql);
void getinvertdirname(char* dirname);
bool isEmptyDir(int id,MYSQL* mysql);
int cdFunc(const char* user, const char* arg, int* curr_folder, MYSQL* mysql);
int pwd(char* working_dir, int curr_folder, MYSQL* mysql);
int lsFunc(char* msg, const char* user, const char* arg, int curr_folder, MYSQL* mysql);
int removeFunc(int id_now,const char *arg,const char* user,MYSQL *mysql);
int putsTextFunc(const char* username, const char* arg,int netfd, MYSQL * mysql, int id_now );
int getsTextFunc(const char* arg, int retM,int netfd );
int getsFunc(const char* user, const char* arg, int curr_folder, int netfd, MYSQL* mysql);
#endif
